package com.smm.controller;

import com.jn.sqlhelper.dialect.pagination.PagingResult;
import com.smm.common.Result;
import com.smm.entity.Song;
import com.smm.service.SongService;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("song")
@Api(value = "smm", tags = "Song相关接口")
public class SongController {

    private static Logger log = LoggerFactory.getLogger(SongController.class);
    @Resource
    SongService songService;

    @PostMapping("/")
    public Result addSong(Song song) {
        return Result.SUCCESS(songService.addSong(song));
    }

    @DeleteMapping("/{id}")
    public Result deleteSong(@PathVariable("id") Integer id) {

        return Result.SUCCESS(songService.deleteSong(id));
    }

    @GetMapping("/{id}")
    public Result findSong(@PathVariable("id") Integer id) {
        Song song = new Song();
        song.setSongId(id);
        return Result.SUCCESS(songService.findSong(song));
    }

    @PutMapping("/")
    public Result updateSong(@RequestBody Song song) {
        log.info(String.valueOf(song));
        return Result.SUCCESS(songService.updateSong(song));
    }

    @GetMapping("/{pageSize}/{pageNumber}")
    public Result findUserPage(@PathVariable("pageSize") Integer pageSize,
                               @PathVariable("pageNumber") Integer pageNumber,
                               Song song) {
        PagingResult songs = songService.findSongPage(song, pageSize, pageNumber);
        return Result.SUCCESS(songs);

    }

    @GetMapping("/singer")
    public Result getSinger() {
        PagingResult songs = songService.findSongPage(null, 5, 1);
        return Result.SUCCESS(songs);
    }
}
